package com.example.administrator.democ;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class EditActivity extends AppCompatActivity {
    private TextView txtNo;
    private EditText edtAndroid;
    private EditText edtEnglish;
    private Button btnSave;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit);

        findViews();
        initData();
        initSave();
    }

    private void initSave() {
        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String no = txtNo.getText().toString();
                int android = Integer.parseInt(edtAndroid.getText().toString());
                int english = Integer.parseInt(edtEnglish.getText().toString());

                Score score = new Score(no, android, english);

                Intent intent = new Intent();
                intent.putExtra("SCO", score);
                setResult(3001, intent);
                finish();
            }
        });
    }

    private void initData() {
        Intent intent = getIntent();
        Score score = (Score) intent.getSerializableExtra("Score");
        txtNo.setText(score.getStuNo());
        edtAndroid.setText(String.valueOf(score.getAndroid()));
        edtEnglish.setText(String.valueOf(score.getEnglish()));
    }

    private void findViews() {
        txtNo = findViewById(R.id.txt_no);
        edtAndroid = findViewById(R.id.edt_android);
        edtEnglish = findViewById(R.id.edt_english);
        btnSave = findViewById(R.id.btn_save);
    }
}
